from weibo1 import APIClient, OAuthToken
import weibo_common
import webbrowser

app_key = weibo_common.APP_KEY
app_secret = weibo_common.APP_SECRET
callback_url = weibo_common.CALLBACK_URL

client = APIClient(app_key=app_key, app_secret=app_secret, callback=callback_url)
request_token = client.get_request_token()
#save_request_token_to_db(request_token.oauth_token, request_token.oauth_token_secret)
url = client.get_authorize_url(request_token)
# TODO: redirect to url

url = 'http://api.t.sina.com.cn/oauth/authorize?oauth_token=' + request_token.oauth_token
print('url' + url);

webbrowser.open(url);
oauth_verifier = raw_input('verifier:').strip()

request_token = OAuthToken(request_token.oauth_token, request_token.oauth_token_secret, oauth_verifier)

client = APIClient(app_key=app_key, app_secret=app_secret, token=request_token)
access_token = client.get_access_token()
weibo_common.save_access_token(access_token)
